<template>
  <div class="feeds-item" @click="$router.push('/feeds/' + feed_id)">
    <div class="feeds-pic">
      <van-image :src="pic_url">
        <template v-slot:loading>
          <img src="@/assets/goImages/8P.png" />
        </template>
      </van-image>
    </div>
    <div class="feeds-info">
      <span class="title">{{ title }}</span>
      <span class="address">{{ name }}<i v-if="name">·</i>{{ time }}</span>
      <div class="price-container">
        <div class="price-box">
          <span class="price">{{ price_desc }}</span>
          <span class="plus-icon" v-if="card_price">
            <van-icon size="16px" color="#C7993A" name="arrow-down" />
          </span>
          <span class="plus-price">{{ plus_price }}</span>
        </div>
        <div class="view-count">{{ getCount(view_count) }}人看过</div>
      </div>
      <div class="source">{{ reason_text }}</div>
      <div class="preview" v-if="post_covers" @click.stop="sidePic">
        <div class="pre-pic-item" v-for="(pic, index) in post_covers.slice(0, 4)" :key="index">
          <van-image :src="pic.gif_url || pic.url">
            <template v-slot:loading>
              <img src="@/assets/goImages/8P.png" alt="" />
            </template>
          </van-image>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { bus } from '@/utils/bus/bus'
export default {
  props: {
    pic_url: String,
    title: String,
    name: String,
    tiny_title: String,
    time: String,
    feed_id: Number,
    price_desc: String,
    card_price: String,
    plus_price: String,
    view_count: Number,
    reason_text: String,
    post_covers: [Array, undefined, null]
  },
  methods: {
    getCount(count) {
      if (count < 10000) {
        return count
      } else {
        const re = /^\d+\.?\d?/
        let res = count / 10000 + ''
        return parseFloat(res.match(re)) + '万'
      }
    },
    sidePic() {
      this.$router.push('/posts/' + this.feed_id)
    }
  },
  beforeDestroy() {
    bus.$emit('send-info', { tiny_title: this.tiny_title, pic_url: this.pic_url, name: this.name, time: this.time, id: this.feed_id })
  }
}
</script>

<style lang="less" scoped>
.feeds-item {
  display: flex;
  margin-bottom: 20px;

  .feeds-pic {
    width: 120px;
    overflow: hidden;

    ::v-deep .van-image {
      height: 100%;
      width: 100%;
      img {
        height: 100px;
        width: 100%;
        border-radius: 10px;
      }
    }
  }

  .feeds-info {
    padding-left: 5px;
    padding-top: 5px;
    flex: 1;
    display: flex;
    flex-direction: column;

    .title {
      width: 100%;
      font-size: 16px;
      line-height: 18px;
      font-weight: 600;
      color: #333;
      overflow: hidden;
      text-overflow: ellipsis; /*显示为......*/
      -webkit-line-clamp: 2; /*显示为两行，在第二行中显示为.......*/
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .address {
      padding: 7px 0;
      font-size: 12px;
      color: #777;

      i {
        padding: 0 2px;
        font-weight: 900;
      }
    }

    .price-container {
      padding: 5px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .price-box {
        font-size: 12px;
        align-items: inherit;
        display: inherit;

        .price {
          color: #1d1c1b;
          font-weight: 600;
          margin-right: 10px;
        }
        .plus-icon {
          height: 16px;
          width: 16px;
          margin-right: 5px;
          background-color: #1d1c1b;
          border-radius: 999px;

          .van-icon {
            font-weight: 700;
            transform: scale(0.6, 1.2);
          }
        }
        .plus-price {
          font-weight: 600;
          color: #c7993a;
        }
      }
      .view-count {
        padding-right: 5px;
        color: #bfbfbf;
        font-size: 12px;
        line-height: 16px;
      }
    }
    .source {
      color: #76c1e7;
      background-color: #f7f9fa;
      padding: 5px 0 10px;
      padding-left: 10px;
      font-size: 12px;
      font-weight: 500;
    }
    .preview {
      margin-top: 2px;
      display: flex;
      flex-wrap: wrap;

      .pre-pic-item {
        margin-right: 5px;
        width: 45px;
        height: 45px;

        ::v-deep .van-image {
          height: 100%;
          width: 100%;
          img {
            height: 100%;
            width: 100%;
          }
        }
      }
    }
  }
}
</style>
